package org.vergil.restful;

import org.apache.activemq.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.JMSException;
import javax.jms.Session;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by vergil on 5/1/17.
 */
@RestController
public class TestRestFul {

    @Autowired
    private JmsTemplate jmsTemplate;

    @RequestMapping("/test")
    public Map test() {
        Map<String, Object> map = new HashMap<>();
        map.put("info", 8);
        map.put("tag","true");
        String message = "test to client";
        jmsTemplate.send("devTest", new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return (Message) session.createTextMessage(message);
            }
        });
        return map;
    }
}
